from django.db import models

# Create your models here.
from core.models import CoreModel

class Level(models.TextChoices):
    EASY = 'E', 'Easy'
    MEDIUM = 'M', 'Medium'
    HARD = 'H', 'Hard'
    
class Type(models.TextChoices):
    SINGLE = 'S', 'Single'
    MULTIPLE = 'M', 'Multiple'
    JUDGE = 'J', 'Judge'


class QuestionLevel(models.Model):
    name = models.CharField(max_length=64, help_text='题目难易度名称')
    tag = models.CharField(choices=Level.choices, max_length=1, unique=True, help_text='题目难易标签')

    class Meta:
        db_table = 'question_level'
        verbose_name = "题目难度管理"
        verbose_name_plural = verbose_name
        ordering = ("id",)
        
    def __str__(self):
        return self.name
    
       
class QuestionType(models.Model):
    name = models.CharField(max_length=64, help_text='题目类型名称')
    tag = models.CharField(choices=Type.choices, max_length=1, unique=True, help_text='题目类型标签')

    class Meta:
        db_table = 'question_type'
        verbose_name = "题目类型管理"
        verbose_name_plural = verbose_name
        ordering = ("id",)
        
    def __str__(self):
        return self.name
    
    
class QuestionCategory(CoreModel):
    name = models.CharField(max_length=64, help_text='问题类别名称')
    tag = models.CharField(max_length=32, unique=True, help_text='问题类别标签')

    class Meta:
        db_table = 'question_category'
        verbose_name = "题目分类管理"
        verbose_name_plural = verbose_name
        ordering = ("id",)
        
    def __str__(self):
        return self.name
    
    
class QuestionOption(CoreModel):
    text = models.CharField(max_length=512, help_text='选项的纯文本内容')
    content = models.CharField(max_length=512, help_text='选项的html格式内容')

    class Meta:
        db_table = 'question_option'
        verbose_name = "题目描述管理"
        verbose_name_plural = verbose_name
        
        
                  
class Question(CoreModel):
    content = models.TextField(help_text='题目内容')
    option_ids = models.JSONField(null=True, blank=True, default=None, help_text='题目的选项,用选项的id用-连在一起表示答案')
    anser_ids = models.JSONField(null=True, blank=True, default=None, help_text='题目的选项,用选项的id用-连在一起表示答案')

    level_tag = models.ForeignKey(QuestionLevel, to_field='tag', on_delete=models.DO_NOTHING, default=Level.EASY, help_text='题目难易度级别')
    type_tag = models.ForeignKey(QuestionType, to_field='tag', on_delete=models.DO_NOTHING, default=Type.SINGLE, help_text='题目类型')
    category_tag = models.ForeignKey(QuestionCategory, to_field='tag', on_delete=models.DO_NOTHING, default='other', help_text='题目类型')

    class Meta:
        db_table = 'question'
        verbose_name = "题目管理"
        verbose_name_plural = verbose_name
        ordering = ("id",)
